package example.service.impl;

import com.alibaba.fastjson.JSON;
import example.common.Result;
import example.dto.SecondmentInfoDTO;
import example.entity.SecondmentHeadInfo;
import example.mapper.SecondmentHeadInfoMapper;
import example.service.ISecondmentHeadInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

@Service
public class SecondmentHeadInfoServiceImpl implements ISecondmentHeadInfoService {

    @Resource
    private SecondmentHeadInfoMapper secondmentHeadInfoMapper;

    @Override
    public void save(SecondmentHeadInfo secondmentHeadInfo) {
        secondmentHeadInfoMapper.save(secondmentHeadInfo);
    }

    @Override
    public Result listHead(Long secondmentId) {
        String headers =  secondmentHeadInfoMapper.getHeadersBySecondmentId(secondmentId);
        Map afterHeadersMap = JSON.parseObject(headers, Map.class);
        return Result.ok(afterHeadersMap);
    }

    @Override
    public int checkSecondmentIdExists(Long secondmentId){
        return secondmentHeadInfoMapper.checkSecondmentIdExists(secondmentId);
    }
}
